package net.xiduth.game.player.content.events.raiding;

import java.util.TimerTask;

import net.xiduth.cores.CoresManager;
import net.xiduth.game.World;
import net.xiduth.game.WorldTile;
import net.xiduth.game.npc.NPC;
import net.xiduth.utils.Logger;

/**
 * 
 * @author Jae <jae@xiduth.com>
 * 
 * @since <Oct 17, 2013>
 *
 */
public class MiscEvent {
	
	public static void load() {
		initForestRoc();
		initOceanPQ();
		initHillsGuard();
		initVillageBlink();
	}
	
	public static void initVillageBlink() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					refreshBlink();
					World.sendWorldMessage("<img=7><col=FF000>News: Blink has arrived in the 'Village' area!", false);
					World.spawnNPC(12878, new WorldTile(2528, 3301, 0), -1,
							true, true);
					Logger.log("Misc.", "Blink initiated.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
			}, 0, 1800000);
	}
	
	public static void initForestRoc() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					refreshRoc();
					World.sendWorldMessage("<img=7><col=FF000>News: Roc has arrived in the 'Forest' area!", false);
					World.spawnNPC(4972, new WorldTile(3697, 3047, 0), -1,
							true, true);
					Logger.log("Misc.", "Forest Roc initiated.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
			}, 0, 1800000);
		}

	public static void initOceanPQ() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					refreshPQ();
					World.sendWorldMessage("<img=7><col=FF000>News: Pest Queen has arrived in the 'Ocean' area!", false);
					World.spawnNPC(6358, new WorldTile(3745, 2955, 0), -1,
							true, true);
					Logger.log("Misc.", "Forest Roc initiated.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
			}, 0, 2200000);
		}
	
	public static void initHillsGuard() {
		CoresManager.fastExecutor.schedule(new TimerTask() {
			@Override
			public void run() {
				try {
					refreshGuard();
					World.sendWorldMessage("<img=7><col=FF000>News: A Guard has arrived in the 'Hills' area!", false);
					World.spawnNPC(15126, new WorldTile(3306, 3265, 0), -1,
							true, true);
					Logger.log("Guard", "Hills Guard initiated.");
				} catch (Throwable e) {
					Logger.handle(e);
				}
			}
			}, 0, 1800000);
		}
	
	public static final void refreshGuard() {
		for (NPC n : World.getNPCs()) {
			if (n == null || n.getId() != 15126)
				continue;
			n.sendDeath(n);
		}
		Logger.log("Guard", "Refresh task completed.");
	}
	
	public static final void refreshPQ() {
		for (NPC n : World.getNPCs()) {
			if (n == null || n.getId() != 6358)
				continue;
			n.sendDeath(n);
		}
		Logger.log("PQ", "Refresh task completed.");
	}
	
	public static final void refreshRoc() {
		for (NPC n : World.getNPCs()) {
			if (n == null || n.getId() != 4972)
				continue;
			n.sendDeath(n);
		}
		Logger.log("Roc", "Refresh task completed.");
	}
	
	public static final void refreshBlink() {
		for (NPC n : World.getNPCs()) {
			if (n == null || n.getId() != 12878)
				continue;
		n.sendDeath(n);
		}
	}
}